<?php
/**
 * Commodity Controller.
 *
 * @author Nguyen Hai Ha
 * @version 1.0
 */

class Member_CommodityController extends Zend_Controller_Action {
	protected $_baseUrl;
	protected $_contextPath;
	protected $_utilities;
	protected $_auth;
	protected $_acl;
	protected $_errors;

	public function init() {
		$this->_baseUrl = $this->_request->getBaseURL ();
		$this->_contextPath = "member/commodity";

		$this->view->assign ( "baseUrl", $this->_baseUrl );
		$this->view->assign ( "contextPath", $this->_contextPath );

		$this->_utilities = new Utilities ( );
		$this->view->assign ( "utilities", $this->_utilities );

		$this->_auth = Zend_Auth::getInstance ()->getIdentity ();

		/** Get our Action Helper */
		$this->_acl = $this->_helper->getHelper ( 'acl' );

		$this->_errors = array();
	}

	public function indexAction() {
		$this->_redirect ( $this->_contextPath . "/posted-sell" );
	}

	public function expiredBuyAction(){}
	
	public function expiredSellAction(){}

	public function postBuyAction(){
		$statusModel = new StatusModel ( );
		$catagoryModel = new CategoryModel ( );
		$sectionModel = new SectionModel ( );
		$eway_catagory = $catagoryModel->getAll ();
		$sections = $sectionModel->getAll ();

		$this->view->assign ( "catagories", $eway_catagory );
		$this->view->assign ( "sections", $sections );

		if ($this->_request->isPost ()) {
			$request = $this->getRequest ();
				
			$com_name = ( string ) $request->getPost ( "name" );
			$com_description = ( string ) $request->getPost ( "description" );
			$com_price = ( string ) $request->getPost ( "price" );
			$com_vip = ( int ) $request->getPost ( "vip" );
			$com_banned = 0;
			$com_user = $this->_auth->usr_mobile;
			$com_hit = 0;
			$categories = $request->getPost ( "category" );
			$section_id = ( int ) $request->getPost ( "section" );
				
			$exprite_date = date('Y-m-d', mktime(0, 0, 0, date("m")+1, date("d"), date("Y")));
				
			$commodity = array (
				'com_name' => $com_name, 
				'com_description' => $com_description, 
				'com_price' => $com_price, 
				'com_user' => $com_user, 
				'com_banned' => $com_banned, 
				'com_vip' => $com_vip, 
				'com_hit' => $com_hit, 
				'com_type'=>0,
				'com_expired_date' => $exprite_date
			);

			if ($section_id)
			$price_down = (int) $sectionModel->getPriceBySectionId($section_id);
			/** Kiem tra xem tai khoan cua user con du tien khong */
			$user_id = $this->_auth->usr_id;
				
			$userModel = new UserModel ( );
			$account = $userModel->getUserById ( $user_id );
			if (isset($price_down))
			if ( (int) $account->usr_coin_amount < (int) $price_down)
			$this->_errors['not_enough_money'] = "Ban khong con du tien de dang ky san pham trong chuyen muc nay.";

			if (strlen($com_name) == "")
			$this->_errors['name_null'] = "Ban phia nhap ten san pham.";
			if (strlen($com_price) == "" )
			$this->_errors['price_null'] = "Ban phai nhap gia cho san pham";
			if (count($categories) == 0)
			$this->_errors['category_null'] = "Ban phai chon category.";
				
			if (count($this->_errors)){
				$this->view->assign("selected_categories", $categories);
				$this->view->assign("commodity", $commodity);
				$this->view->assign("section_id", $section_id);
				$this->view->assign ( "errors", $this->_errors );
				$this->render ( "post-buy" );
				return;
			}
				
			$catcomModel = new CatcomModel ( );
			$comModel = new CommodityModel ( );
			/** neu nguoi dung co chon category thi moi insert xuong database */
			if (count ( $categories )) {
				$lastId = $comModel->insertCommodity ( $commodity );
				for($i = 0; $i < count ( $categories ); $i ++) {
					$catcom = array ('cat_id' => $categories [$i], 'com_id' => $lastId );
					$catcomModel->insertCatcom ( $catcom );
				}

				/** Tru tien trong tai khoan cua khach hang */
				$total_amount = (int) $account->usr_coin_amount;
				$coin_amount_again = $total_amount - $price_down;
				$userModel->update(array('usr_coin_amount'=>$coin_amount_again), $user_id);

				/** Cap nhat toi bang history */
				$history = new HistoryModel();
				$his = array(
					'his_user' => $this->_auth->usr_mobile,
					'his_action' => 'post_commodity',
					'his_amount' => $price_down
				);
				$history->insert($his);

				// Do upload image.
				$folder = $_SERVER ['DOCUMENT_ROOT'] . '/' . $this->_baseUrl . "/public/images/commodity/";
				$images = $_FILES ['image_file'];
				$imageModel = new ImageModel();
				foreach ($images['name'] as $key => $value) {
					if(!empty($value))
					{
						$image['name'] = $value;
						$image['tmp_name'] = $images['tmp_name'][$key];
						$image_name = $this->_utilities->uploadImage ( $image, $folder );
						$image_data = array(
							'com_id' => $lastId, 
							'img_title' => $image_name,
							'img_path' => $this->_baseUrl . "/public/images/commodity/"
							);
							$imageModel->insert($image_data);
					}
				}
			}

			$this->_redirect ( $this->_contextPath . "/posted-buy" );
		}

		$commodity = array ('com_name' => '', 'com_description' => '', 'com_status' => '', 'com_avail' => 2, 'com_price' => '', 'com_user' => '', 'com_banned' => '', 'com_vip' => '', 'com_hit' => '' );
		$this->view->assign( "commodity", $commodity );
		$this->render("post-buy");
	}

	public function postedBuyAction(){
		$account = $this->_auth->usr_mobile;
		$comModel = new CommodityModel ( );

		/** Begin: render script for paging. */
		$paging = new Paging ( );
		/**
		 * Get item on page.
		 * Get total page.
		 */
		$itemPerPage = Constant::COMMODITY_LIST_ITEM;
		$totalRecords = $comModel->getTotalRecordsMemberBuy ( $account );
		$currentPages = ( int ) $this->_request->getParam ( 'page' );
		if ($currentPages == 0)
		$currentPages = 1;
		/**
		 * Set url for paging.
		 * Render paging for page.
		 */
		$url = $this->_baseUrl . "/" . $this->_contextPath . "/posted-buy";
		$page = $paging->doPaging ( $totalRecords, $url, $currentPages, $itemPerPage );
		$page_title = $paging->doPageSeparator ( $totalRecords, $currentPages, $itemPerPage );
		/** Set param for view. */
		$this->view->assign ( "page", $page );
		$this->view->assign ( "page_title", $page_title );
		$this->view->assign ( "currentPage", $currentPages );
		/** End: render script for paging. */

		$commodities = $comModel->getAllCommodityMemberBuy ( $account, $currentPages, $itemPerPage );

		$this->view->assign ( "commodities", $commodities );
		$this->render ( "posted-buy" );
	}

	public function viewAction(){
		$com_id = ( int ) $this->_request->getParam ( "id" );
		$comModel = new CommodityModel ( );
		$commodity = $comModel->getCommodityById ( $com_id );

		/** Validate if the user is the owner */
		if (($commodity->com_user != $this->_auth->usr_mobile)) {
			$this->_acl->denyAccess ();
		}

		$statusModel = new StatusModel();
		$status = $statusModel->getStatusById($commodity->com_status);
		$imageModel = new ImageModel();
		$images = $imageModel->getImageByComId($commodity->com_id);

		$this->view->assign("commodity", $commodity);
		$this->view->assign("images", $images);
		$this->view->assign("status", $status);
		if ($commodity->com_type==0)
			$this->render("view-buy");
		else
			$this->render("view-sell");
	}

	public function postedSellAction() {
		$account = $this->_auth->usr_mobile;
		$comModel = new CommodityModel ( );

		/** Begin: render script for paging. */
		$paging = new Paging ( );
		/**
		 * Get item on page.
		 * Get total page.
		 */
		$itemPerPage = Constant::COMMODITY_LIST_ITEM;
		$totalRecords = $comModel->getTotalRecordsMember ( $account );
		$currentPages = ( int ) $this->_request->getParam ( 'page' );
		if ($currentPages == 0)
		$currentPages = 1;
		/**
		 * Set url for paging.
		 * Render paging for page.
		 */
		$url = $this->_baseUrl . "/" . $this->_contextPath . "/posted-sell";
		$page = $paging->doPaging ( $totalRecords, $url, $currentPages, $itemPerPage );
		$page_title = $paging->doPageSeparator ( $totalRecords, $currentPages, $itemPerPage );
		/** Set param for view. */
		$this->view->assign ( "page", $page );
		$this->view->assign ( "page_title", $page_title );
		$this->view->assign ( "currentPage", $currentPages );
		/** End: render script for paging. */

		$commodities = $comModel->getAllCommodityMember ( $account, $currentPages, $itemPerPage );

		$this->view->assign ( "commodities", $commodities );
		$this->render ( "posted-sell" );
	}

	public function bannedBuyAction() {
		$account = $this->_auth->usr_mobile;
		$comModel = new CommodityModel ( );

		/** Begin: render script for paging. */
		$paging = new Paging ( );
		/**
		 * Get item on page.
		 * Get total page.
		 */
		$itemPerPage = Constant::COMMODITY_LIST_ITEM;
		$totalRecords = $comModel->getTotalRecordsBannedBuy ( $account );
		$currentPages = ( int ) $this->_request->getParam ( 'page' );
		if ($currentPages == 0)
		$currentPages = 1;
		/**
		 * Set url for paging.
		 * Render paging for page.
		 */
		$url = $this->_baseUrl . "/" . $this->_contextPath . "/banned-buy";
		$page = $paging->doPaging ( $totalRecords, $url, $currentPages, $itemPerPage );
		$page_title = $paging->doPageSeparator ( $totalRecords, $currentPages, $itemPerPage );
		/** Set param for view. */
		$this->view->assign ( "page", $page );
		$this->view->assign ( "page_title", $page_title );
		$this->view->assign ( "currentPage", $currentPages );
		/** End: render script for paging. */

		$commodities = $comModel->getAllCommodityBannedBuy ( $account, $currentPages, $itemPerPage );

		$this->view->assign ( "commodities", $commodities );
		$this->render ( "banned-buy" );
	}

	public function bannedSellAction() {
		$account = $this->_auth->usr_mobile;
		$comModel = new CommodityModel ( );

		/** Begin: render script for paging. */
		$paging = new Paging ( );
		/**
		 * Get item on page.
		 * Get total page.
		 */
		$itemPerPage = Constant::COMMODITY_LIST_ITEM;
		$totalRecords = $comModel->getTotalRecordsBanned ( $account );
		$currentPages = ( int ) $this->_request->getParam ( 'page' );
		if ($currentPages == 0)
		$currentPages = 1;
		/**
		 * Set url for paging.
		 * Render paging for page.
		 */
		$url = $this->_baseUrl . "/" . $this->_contextPath . "/banned-sell";
		$page = $paging->doPaging ( $totalRecords, $url, $currentPages, $itemPerPage );
		$page_title = $paging->doPageSeparator ( $totalRecords, $currentPages, $itemPerPage );
		/** Set param for view. */
		$this->view->assign ( "page", $page );
		$this->view->assign ( "page_title", $page_title );
		$this->view->assign ( "currentPage", $currentPages );
		/** End: render script for paging. */

		$commodities = $comModel->getAllCommodityBanned ( $account, $currentPages, $itemPerPage );

		$this->view->assign ( "commodities", $commodities );
		$this->render ( "banned-sell" );
	}

	public function postSellAction() {
		$statusModel = new StatusModel ( );
		$catagoryModel = new CategoryModel ( );
		$sectionModel = new SectionModel ( );
		$eway_status = $statusModel->getAll ();
		$eway_catagory = $catagoryModel->getAll ();
		$sections = $sectionModel->getAll ();

		$this->view->assign ( "catagories", $eway_catagory );
		$this->view->assign ( "eway_status", $eway_status );
		$this->view->assign ( "sections", $sections );

		if ($this->_request->isPost ()) {
			$request = $this->getRequest ();
				
			$com_name = ( string ) $request->getPost ( "name" );
			$com_description = ( string ) $request->getPost ( "description" );
			$com_status = ( int ) $request->getPost ( "status" );
			$com_avail = ( int ) $request->getPost ( "avail" );
			$com_price = ( string ) $request->getPost ( "price" );
			$com_vip = ( int ) $request->getPost ( "vip" );
			$com_banned = 0;
			$com_user = $this->_auth->usr_mobile;
			$com_hit = 0;
			$categories = $request->getPost ( "category" );
				
			$exprite_date = date('Y-m-d', mktime(0, 0, 0, date("m")+1, date("d"),   date("Y")));
				
			$commodity = array (
				'com_name' => $com_name, 
				'com_description' => $com_description, 
				'com_status' => $com_status, 
				'com_avail' => $com_avail, 
				'com_price' => $com_price, 
				'com_user' => $com_user, 
				'com_banned' => $com_banned, 
				'com_vip' => $com_vip, 
				'com_hit' => $com_hit, 
				'com_type'=>1,
				'com_expired_date' => $exprite_date
			);

			/** Kiem tra xem tai khoan cua user con du tien khong */
			if (count ( $categories )){
				$list_cat_id = "(";
				for ($i=0; $i<count($categories); $i++){
					if ($i != count($categories)-1) 
						$list_cat_id .= $categories[$i].",";
					else
						$list_cat_id .= $categories[$i];
				}	
				$list_cat_id .= ")";
				
				$list_sections = $catagoryModel->getAllSectionByCatId($list_cat_id);
				$price_down = 0;
				foreach ($list_sections as $list) {
					$price_down += (int) $sectionModel->getPriceBySectionId($list->sec_id);
				}
			}
			
			$user_id = $this->_auth->usr_id;
			$userModel = new UserModel ( );
			$account = $userModel->getUserById ( $user_id );

			if (isset($price_down)){
				if ( (int) $account->usr_coin_amount < (int) $price_down)
					$this->_errors['not_enough_money'] = "Ban khong con du tien de dang ky san pham trong chuyen muc nay.";
			}

			if (strlen($com_name) == "")
			$this->_errors['name_null'] = "Ban phia nhap ten san pham.";
			if ($com_status == 0)
			$this->_errors['status_null'] = "Ban phai chon status";
			if ($com_avail == 2)
			$this->_errors['avail_null'] = "Ban phai chon avail";
			if (strlen($com_price) == "" )
			$this->_errors['price_null'] = "Ban phai nhap gia cho san pham";
			if (count($categories) == 0)
			$this->_errors['category_null'] = "Ban phai chon category.";
				
			if (count($this->_errors)){
				$this->view->assign("selected_categories", $categories);
				$this->view->assign("commodity", $commodity);				
				$this->view->assign ( "errors", $this->_errors );
				$this->render ( "post-sell" );
				return;
			}
				
			$catcomModel = new CatcomModel ( );
			$comModel = new CommodityModel ( );
			/** neu nguoi dung co chon category thi moi insert xuong database */
			if (count ( $categories )) {
				$lastId = $comModel->insertCommodity ( $commodity );
				for($i = 0; $i < count ( $categories ); $i ++) {
					$catcom = array ('cat_id' => $categories [$i], 'com_id' => $lastId );
					$catcomModel->insertCatcom ( $catcom );
				}

				/** Tru tien trong tai khoan cua khach hang */
				$total_amount = (int) $account->usr_coin_amount;
				$coin_amount_again = $total_amount - $price_down;
				$userModel->update(array('usr_coin_amount'=>$coin_amount_again), $user_id);

				/** Cap nhat toi bang history */
				$history = new HistoryModel();
				$his = array(
					'his_user' => $this->_auth->usr_mobile,
					'his_action' => 'post_commodity',
					'his_amount' => $price_down
				);
				$history->insert($his);

				// Do upload image.
				$folder = $_SERVER ['DOCUMENT_ROOT'] . '/' . $this->_baseUrl . "/public/images/commodity/";
				$images = $_FILES ['image_file'];
				$imageModel = new ImageModel();
				foreach ($images['name'] as $key => $value) {
					if(!empty($value))
					{
						$image['name'] = $value;
						$image['tmp_name'] = $images['tmp_name'][$key];
						$image_name = $this->_utilities->uploadImage ( $image, $folder );
						$image_data = array(
							'com_id' => $lastId, 
							'img_title' => $image_name,
							'img_path' => $this->_baseUrl . "/public/images/commodity/"
							);
							$imageModel->insert($image_data);
					}
				}
			}

			$this->_redirect ( $this->_contextPath );
		}

		$commodity = array ('com_name' => '', 'com_description' => '', 'com_status' => '', 'com_avail' => 2, 'com_price' => '', 'com_user' => '', 'com_banned' => '', 'com_vip' => '', 'com_hit' => '' );
		$this->view->assign( "commodity", $commodity );
		$this->render ( "post-sell" );
	}

	public function editSellAction() {

		$statusModel = new StatusModel ( );
		$categoryModel = new CategoryModel ( );
		$sectionModel = new SectionModel ( );
		$eway_status = $statusModel->getAll ();
		$eway_category = $categoryModel->getAll ();
		$sections = $sectionModel->getAll ();
		
		$this->view->assign ( "sections", $sections );
		$this->view->assign ( "categories", $eway_category );
		$this->view->assign ( "eway_status", $eway_status );

		if ($this->_request->isPost ()) {
			$request = $this->getRequest ();
				
			$com_name = ( string ) $request->getPost ( "name" );
			$com_description = ( string ) $request->getPost ( "description" );
			$com_status = ( int ) $request->getPost ( "status" );
			$com_avail = ( int ) $request->getPost ( "avail" );
			$com_price = ( string ) $request->getPost ( "price" );
			$com_vip = ( int ) $request->getPost ( "vip" );
			$com_user = $this->_auth->usr_mobile;
			$com_posted_date = ( string ) $request->getPost ( "posted_date" );
			$com_id = ( int ) $request->getPost ( "id" );
				
			$commodity = array (
				'com_name' => $com_name, 
				'com_description' => $com_description, 
				'com_status' => $com_status, 
				'com_avail' => $com_avail, 
				'com_price' => $com_price, 
				'com_user' => $com_user, 
				'com_vip' => $com_vip, 
				'com_posted_date' => $com_posted_date 
			);
				
			$categories = $request->getPost ( "category" );
			
			if (strlen($com_name) == "")
			$this->_errors['name_null'] = "Ban phia nhap ten san pham.";
			if ($com_status == 0)
			$this->_errors['status_null'] = "Ban phai chon status";
			if ($com_avail == 2)
			$this->_errors['avail_null'] = "Ban phai chon avail";
			if (strlen($com_price) == "" )
			$this->_errors['price_null'] = "Ban phai nhap gia cho san pham";
			if (count($categories) == 0)
			$this->_errors['category_null'] = "Ban phai chon category.";
				
			if (count($this->_errors)){
				$this->view->assign("com_categories", $categories);
				$this->view->assign("commodity", $commodity);				
				$this->view->assign ( "errors", $this->_errors );
				$this->render ( "edit-sell" );
				return;
			}
			
			$catcomModel = new CatcomModel ( );
			$comModel = new CommodityModel ( );
			if (count ( $categories )) {
				/** Update du lieu. */
				$comModel->updateCommodity ( $commodity, $com_id );
				/** Delete het du lieu cu cua id nay trong bang catcom. */
				$catcomModel->deleteByComId ( $com_id );
				/** Insert du lieu moi xuong bang catcom. */
				for($i = 0; $i < count ( $categories ); $i ++) {
					$catcom = array ('cat_id' => $categories [$i], 'com_id' => $com_id );
					$catcomModel->insertCatcom ( $catcom );
				}

				// Do upload image.
				$folder = $_SERVER ['DOCUMENT_ROOT'] . '/' . $this->_baseUrl . "/public/images/commodity/";
				$images = $_FILES ['image_file'];
				$imageModel = new ImageModel();
				foreach ($images['name'] as $key => $value) {
					if(!empty($value))
					{
						$image['name'] = $value;
						$image['tmp_name'] = $images['tmp_name'][$key];
						$image_name = $this->_utilities->uploadImage ( $image, $folder );
						$image_data = array(
							'com_id' => $com_id, 
							'img_title' => $image_name,
							'img_path' => $this->_baseUrl . "/public/images/commodity/"
							);
							$imageModel->insert($image_data);
					}
				}
			}
				
			$this->_redirect ( $this->_contextPath . "/posted-sell" );
		}

		$com_id = ( int ) $this->_request->getParam ( "id" );
		$comModel = new CommodityModel ( );
		$catcomModel = new CatcomModel ( );
		$commodity = $comModel->getCommodityById ( $com_id );
		$com_categories = $catcomModel->getAllByComId ( $com_id );

		/** Validate if the user is the owner */
		if (($commodity->com_user != $this->_auth->usr_mobile)) {
			$this->_acl->denyAccess ();
		}

		$this->view->assign ( "commodity", $commodity );
		$this->view->assign ( "com_categories", $com_categories );
		// Render view.
		$this->render ( "edit-sell" );
	}
	
	public function editBuyAction() {

		$statusModel = new StatusModel ( );
		$categoryModel = new CategoryModel ( );
		$sectionModel = new SectionModel ( );
		$eway_status = $statusModel->getAll ();
		$eway_category = $categoryModel->getAll ();
		$sections = $sectionModel->getAll ();
		
		$this->view->assign ( "sections", $sections );
		$this->view->assign ( "categories", $eway_category );
		$this->view->assign ( "eway_status", $eway_status );

		if ($this->_request->isPost ()) {
			$request = $this->getRequest ();
				
			$com_name = ( string ) $request->getPost ( "name" );
			$com_description = ( string ) $request->getPost ( "description" );
			$com_status = ( int ) $request->getPost ( "status" );
			$com_avail = ( int ) $request->getPost ( "avail" );
			$com_price = ( string ) $request->getPost ( "price" );
			$com_vip = ( int ) $request->getPost ( "vip" );
			$com_user = $this->_auth->usr_mobile;
			$com_posted_date = ( string ) $request->getPost ( "posted_date" );
			$com_id = ( int ) $request->getPost ( "id" );
				
			$commodity = array (
				'com_name' => $com_name, 
				'com_description' => $com_description, 
				'com_status' => $com_status, 
				'com_avail' => $com_avail, 
				'com_price' => $com_price, 
				'com_user' => $com_user, 
				'com_vip' => $com_vip, 
				'com_posted_date' => $com_posted_date 
			);
				
			$categories = $request->getPost ( "category" );
			
			if (strlen($com_name) == "")
			$this->_errors['name_null'] = "Ban phia nhap ten san pham.";
			if ($com_status == 0)
			$this->_errors['status_null'] = "Ban phai chon status";
			if ($com_avail == 2)
			$this->_errors['avail_null'] = "Ban phai chon avail";
			if (strlen($com_price) == "" )
			$this->_errors['price_null'] = "Ban phai nhap gia cho san pham";
			if (count($categories) == 0)
			$this->_errors['category_null'] = "Ban phai chon category.";
				
			if (count($this->_errors)){
				$this->view->assign("com_categories", $categories);
				$this->view->assign("commodity", $commodity);				
				$this->view->assign ( "errors", $this->_errors );
				$this->render ( "edit-buy" );
				return;
			}
			
			$catcomModel = new CatcomModel ( );
			$comModel = new CommodityModel ( );
			if (count ( $categories )) {
				/** Update du lieu. */
				$comModel->updateCommodity ( $commodity, $com_id );
				/** Delete het du lieu cu cua id nay trong bang catcom. */
				$catcomModel->deleteByComId ( $com_id );
				/** Insert du lieu moi xuong bang catcom. */
				for($i = 0; $i < count ( $categories ); $i ++) {
					$catcom = array ('cat_id' => $categories [$i], 'com_id' => $com_id );
					$catcomModel->insertCatcom ( $catcom );
				}

				// Do upload image.
				$folder = $_SERVER ['DOCUMENT_ROOT'] . '/' . $this->_baseUrl . "/public/images/commodity/";
				$images = $_FILES ['image_file'];
				$imageModel = new ImageModel();
				foreach ($images['name'] as $key => $value) {
					if(!empty($value))
					{
						$image['name'] = $value;
						$image['tmp_name'] = $images['tmp_name'][$key];
						$image_name = $this->_utilities->uploadImage ( $image, $folder );
						$image_data = array(
							'com_id' => $com_id, 
							'img_title' => $image_name,
							'img_path' => $this->_baseUrl . "/public/images/commodity/"
							);
							$imageModel->insert($image_data);
					}
				}
			}
				
			$this->_redirect ( $this->_contextPath . "/posted-buy" );
		}

		$com_id = ( int ) $this->_request->getParam ( "id" );
		$comModel = new CommodityModel ( );
		$catcomModel = new CatcomModel ( );
		$commodity = $comModel->getCommodityById ( $com_id );
		$com_categories = $catcomModel->getAllByComId ( $com_id );

		/** Validate if the user is the owner */
		if (($commodity->com_user != $this->_auth->usr_mobile)) {
			$this->_acl->denyAccess ();
		}

		$this->view->assign ( "commodity", $commodity );
		$this->view->assign ( "com_categories", $com_categories );
		// Render view.
		$this->render ( "edit-buy" );
	}

}//End class.